package bz.yfw.example.s3blazeds.part2.helper
{
	import bz.yfw.example.s3blazeds.part2.model.ro.EmpRemotoObject;
	import bz.yfw.example.s3blazeds.part2.model.view.EmpViewModel;
	import bz.yfw.example.s3blazeds.part2.view.EmpEditSecondView;
	
	import org.seasar.akabana.yui.framework.ns.viewpart;
	
	import spark.components.TextArea;
	import spark.components.TextInput;
	import spark.components.supportClasses.ViewReturnObject;
	
	use namespace viewpart;
	
	/**
	 * 社員編集2Helper
	 * @author tokufxug http://twitter.com/tokufxug
	 */ 
	public class EmpEditSecondInitHelper
	{
		public var view:EmpEditSecondView;
		
		viewpart var txtarAddress:TextArea;
		
		viewpart var txtinptTelL:TextInput;
		
		viewpart var txtinptTelC:TextInput;
		
		viewpart var txtinptTelR:TextInput;
		
		viewpart var txtinptEmailL:TextInput;
		
		viewpart var txtinptEmailR:TextInput;
		
		public function get empViewModel():EmpViewModel {
			
			var retObj:ViewReturnObject = view.navigator.poppedViewReturnedObject;
			// 戻るボタン押下後の復元情報
			if (retObj && retObj.object) {
				return retObj.object as EmpViewModel;
			}
			
			// 戻る -> 次へボタン押下後の復元情報 
			if (view.data && view.data is EmpViewModel) {
				return view.data as EmpViewModel;
			}
			return null;
		}
		
		public function reflectEmpModel():void {
			var vm:EmpViewModel = empViewModel;
			if (!vm) {
				return;
			}
			txtarAddress.text = vm.address;
			txtinptTelL.text = vm.telL;
			txtinptTelC.text = vm.telC;
			txtinptTelR.text = vm.telR;
			txtinptEmailL.text = vm.emailL;
			txtinptEmailR.text = vm.emailR;
			
			view.viewModel = vm;
		}
	}
}